import ky from "ky";

export const jsonplaceholder = ky.create({
  prefixUrl: "https://jsonplaceholder.typicode.com",
});
export const API = {
  getPosts: 'posts'
};

export interface PostData {
  id: number,
  userId: number,
  title: string,
  body: string,
  uuid: string
}
export const getPosts = async (page: number, limit: number) => {
  const response = await jsonplaceholder.get<PostData[]>(API.getPosts, {
    searchParams: {
      _start: (page - 1) * limit,
      _limit: limit,
    },
  }).json();
  
  return response;
};